package com.menfan.saas.config;

import com.menfan.saas.common.ResultObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by wangxiangyun on 2017/1/24.
 */
@ControllerAdvice(annotations = RestController.class)
@Slf4j
public class ApiExceptionHandlerAdvice {
    /**
     * Handle exceptions thrown by handlers.
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultObject exception(Exception exception) {
        ResultObject errorResult =new ResultObject();
        errorResult.setMessage(exception.getMessage());
        errorResult.setCode(-1);
        return errorResult;
    }
}
